let $tutu = {
    currentPage: 0, totalPage: 0, pageSize: 10, v: {
        ajaxOption: {method: 'post', dataType: 'json', async: true}, notifyMethod: null, dataTableL: {
            "sProcessing": "处理中...", "sLengthMenu": "显示 _MENU_ 项结果", "sZeroRecords": "没有匹配结果", "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项", "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项", "sInfoFiltered": "(由 _MAX_ 项结果过滤)", "sInfoPostFix": "", "sSearch": "搜索:", "sUrl": "", "sEmptyTable": "表中数据为空", "sLoadingRecords": "载入中...", "sInfoThousands": ",", "oPaginate": {
                "sFirst": "首页", "sPrevious": "上页", "sNext": "下页", "sLast": "末页"
            }, "oAria": {
                "sSortAscending": ": 以升序排列此列", "sSortDescending": ": 以降序排列此列"
            }
        }
    }, notify: function (msg, status) {
        let option = {
            position: "top center", autoHideDelay: 2000, className: status, arrowSize: 10
        };

        $.notify(msg, option);
    }, getRecentDay: function (day) {
        let today = new Date();
        let targetDay_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
        today.setTime(targetDay_milliseconds);

        let tYear = today.getFullYear();
        let tMonth = today.getMonth();
        let tDate = today.getDate();

        tMonth = this.doHandleMonth(tMonth + 1);
        tDate = this.doHandleMonth(tDate);

        return tYear + "-" + tMonth + "-" + tDate;
    }, doHandleMonth: function (month) {
        let m = month;

        if (month.toString().length === 1) m = "0" + month;

        return m;
    }, uiForm: function (data) {
        jQuery('tbody input:checkbox').click(function () {
            if (jQuery(this).is(':checked')) {
                jQuery(this).parent().addClass('checked');
                jQuery(this).parents('tr').addClass('warning');
            } else {
                jQuery(this).parent().removeClass('checked');
                jQuery(this).parents('tr').removeClass('warning');
            }
        });

        $('.checkall').prop('checked', false);

        // 自动记录当前表单显示页码
        let oTable = $("#dataTables").dataTable(); //table1为表格的id
        let tableSettings = oTable.fnSettings();
        let paging_length = tableSettings._iDisplayLength; //当前每页显示多少
        let page_start = tableSettings._iDisplayStart; //当前页开始
        let page = (page_start / paging_length); //得到页数值  比页码小1

        let json = jQuery.parseJSON(data.jqXHR.responseText);

        this.pageSize = paging_length;
        this.currentPage = Number(page) + 1;
        this.totalPage = parseInt((json.total / paging_length) + (json.total % paging_length > 0 ? 1 : 0));

        // 如果当前显示的页码比返回的数据最大页码还大，则直接跳转到第一页
        if (this.totalPage > 0 && this.currentPage > this.totalPage) {
            // 跳转到第一页
            info('页码超出，自动跳转到第一页', 'info');

            setTimeout(function () {
                $('.pagination').children(":first").next().click();
            }, 50);
        }
    }

    , checkAll: function (obj) {
        let parentTable = jQuery(obj).parents('table');
        let ch = parentTable.find('tbody input[type=checkbox]');
        if (jQuery(obj).is(':checked')) {
            ch.each(function () {
                jQuery(this).prop('checked', true);
                jQuery(this).parent().addClass('checked');
                jQuery(this).parents('tr').addClass('warning');
            });
        } else {
            ch.each(function () {
                jQuery(this).removeAttr('checked');
                jQuery(this).parent().removeClass('checked');
                jQuery(this).parents('tr').removeClass('warning');
            });
        }
    }, ajax: function (url, data, callbackFun, option) {
        if (option === null || option === undefined) {
            option = $tutu.v.ajaxOption;
        } else {
            if (option.method === null || option.method === undefined) {
                option.method = $tutu.v.ajaxOption.method;
            }

            if (option.dataType === null || option.dataType === undefined) {
                option.dataType = $tutu.v.ajaxOption.dataType;
            }

            if (option.async === null || option.async === undefined) {
                option.async = $tutu.v.ajaxOption.async;
            }
        }
        jQuery.ajax({
            dataType: option.dataType, url: url, data: data, async: option.async, success: function (data) {
                console.log(data);
                callbackFun(data);
            }, statusCode: {
                401: function () {
                }, 403: function () {
                }, 500: function () {
                }
            }
        });
    }, /**
     * 清理表单参数
     */
    clearForm: function (form) {
        form.find("textarea").val("");
        form.find("input").val("");
        form.find("input[type=checkbox]").removeAttr("checked");
        form.validator("cleanUp");
    }, dataTable: function (obj, option) {
        return obj.dataTable(option);
    }
};

$(document).on('click', '.notifyjs-foo-base .no', function () {
    $(this).trigger('notify-hide');
});
$(document).on('click', '.notifyjs-foo-base .yes', function () {
    if ($tutu.v.notifyMethod != null) {
        eval("$tutu.v.notifyMethod()");
    }
    $(this).trigger('notify-hide');
});

(function ($) {
    $.fn.getInputId = function (sigle) {
        let checkIds = [];

        this.each(function () {
            checkIds.push($(this).val())
        });

        if (sigle) {
            if (checkIds.length > 1) {
                $tutu.notify('只能选择一条记录！', 'error');
                return false;
            } else if (checkIds.length === 0) {
                $tutu.notify('请选择一条记录操作！', 'error');
                return false;
            } else {
                return checkIds[0];
            }
        } else {
            if (checkIds.length === 0) {
                $tutu.notify('请选择至少一条记录操作！', 'error');
                return false;
            } else {
                return checkIds;
            }
        }
    };
})(jQuery);